package org.nw.rapid_framework.generator;

import org.nw.rapid_framework.generator.provider.db.table.model.Table;

/**
 * 适合主子表的上下文
 * 
 * @author xuqc
 * @date 2013-7-28 下午08:19:34
 */
public class Context {

	// 表头的table对象
	Table parentTableObj;
	// 主表
	String parentTable;
	// 子表
	String[] childrenTable;
	// 包名
	String basepackage;
	// 子表关联主表的主键
	String[] parentpk_in_child;

	public Table getParentTableObj() {
		return parentTableObj;
	}

	public void setParentTableObj(Table parentTableObj) {
		this.parentTableObj = parentTableObj;
	}

	public String getParentTable() {
		return parentTable;
	}

	public void setParentTable(String parentTable) {
		this.parentTable = parentTable;
	}

	public String[] getChildrenTable() {
		return childrenTable;
	}

	public void setChildrenTable(String[] childrenTable) {
		this.childrenTable = childrenTable;
	}

	public String getBasepackage() {
		return basepackage;
	}

	public void setBasepackage(String basepackage) {
		this.basepackage = basepackage;
	}

	public String[] getParentpk_in_child() {
		return parentpk_in_child;
	}

	public void setParentpk_in_child(String[] parentpk_in_child) {
		this.parentpk_in_child = parentpk_in_child;
	}

	/**
	 * 判断一个表是否是子表,如果是，那么返回其在子表的位置，如果不是，返回-1
	 * 
	 * @param table
	 * @return
	 */
	public int isChildTable(String table) {
		if(childrenTable != null && childrenTable.length > 0) {
			for(int i = 0; i < childrenTable.length; i++) {
				if(childrenTable[i].equals(table)) {
					return i;
				}
			}
		}
		return -1;
	}
}
